# -*- coding: utf-8 -*-
import os
import psycopg2

# 清空所有es数据

print('Start Delete es Data')
command = """curl -X POST  http://127.0.0.1:9200/noah*/_delete_by_query\?pretty -H 'Content-Type: application/json'  -d'
{
    "query": {
        "match_all": {}
    }
}'"""

error_code = os.system(command)

if error_code == 0:
    print("Es data deleted successfully")
else:
    print(error_code)
    print("Failed to delete es data")

# 清空pg指定表数据

PG_SQL_LOCAL = {
    'database': 'skynet',
    'user': 'postgres',
    'password': "postgres",
    'port': "5432",
    'host': '127.0.0.1'
}

conn = psycopg2.connect(**PG_SQL_LOCAL)
cursor = conn.cursor()
table_list = ['jiangsu_ftp_file_download']
try:
    for tables in table_list:
        sql = "truncate table {0};".format(tables)
        cursor.execute(sql)

    conn.commit()
    print('pgdatabases data deleted successfully')

except Exception as e:
    print('database execute sql error!{0}'.format(e))

finally:
    cursor.close()
    conn.close()
